package com.example.nep.service.impl;

import com.example.nep.dao.AqiFeedbackMapper;
import com.example.nep.model.AqiFeedback;
import com.example.nep.model.Statistics;
import com.example.nep.dao.StatisticsMapper;
import com.example.nep.service.IAqiFeedbackService;
import com.example.nep.service.IStatisticsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author han
 * @since 2024-04-10
 */
@Service
public class StatisticsServiceImpl extends ServiceImpl<StatisticsMapper, Statistics> implements IStatisticsService {

    @Resource
    private AqiFeedbackMapper aqiFeedbackMapper;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateInfo(Statistics statistics) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(new Date());
        String[] s = format.split(" ");
        String confirmDate=s[0];
        String confirmTime=s[1];
        statistics.setConfirmDate(confirmDate);
        statistics.setConfirmTime(confirmTime);
        AqiFeedback aqiFeedback = new AqiFeedback();
        aqiFeedback.setState(2);
        aqiFeedback.setAfId(statistics.getId());
        aqiFeedbackMapper.updateById(aqiFeedback);
        boolean b = updateById(statistics);
        if (b){
            return 1;
        }
        return 0;
    }
}
